<?php
/**
 * 默认接口服务类
 *
 * @author: dogstar <chanzonghuang@gmail.com> 2014-10-04
 */

class Api_Notice extends PhalApi_Api {

	public function getRules() {
        return array(
            'getNotice'=>array(
				'notice_id'=>array('name'=>'NoticeId')
			),
			'setNotice'=>array(
				'notice_id'=>array('name'=>'NoticeId'),
				'notice'=>array('name'=>'Notice'),
				'url'=>array('name'=>'URL')
			)
        );
	}
	
	/**
	     * 接收通知
	     * @desc 接收通知
	     * @return int code 操作码，0表示成功， 1错误
	     * @return object info 信息对象
	     * @return string msg 提示信息
	     */
	public function getNotice() {
	        $rs = array('code' => 0, 'msg' => '', 'info' =>array('a'=>1));
	
	        $domain = new Domain_Notice();
	        $info = $domain->getNotice($this->notice_id);
	
	        if (empty($info)) {
	            DI()->logger->debug('getNotice()','');
	
	            $rs['code'] = 1;
	            $rs['msg'] = T('接收通知失败');
	            return $rs;
	        }
	
	        $rs['info'] = $info;
	        DI()->logger->debug('info of getNotice()', $rs);
	
	        return $rs;
	
	    }
	/**
	     * 设置或添加通知
	     * @desc 当notice_id为空时为添加通知
	     * @return int code 操作码，0表示成功， 1错误
	     * @return object info 信息对象
	     * @return string msg 提示信息
	     */
	public function setNotice() {
	        $rs = array('code' => 0, 'msg' => '', 'info' =>array('a'=>1));

	        $domain = new Domain_Notice();
	        $info = $domain->setNotice($this->notice_id,$this->notice,$this->url);

	        if (empty($info)) {
	            DI()->logger->debug('setNotice()','');

	            $rs['code'] = 1;
	            $rs['msg'] = T('设置添加通知失败');
	            return $rs;
	        }

	        $rs['info'] = $info;
	        DI()->logger->debug('info of setNotice()', $rs);

	        return $rs;

	    }
}